//
//  MyMessageViewController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/7/31.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "MyMessageViewController.h"
#import "MyMessageOneController.h"
#import "MyMessageTwoController.h"


@interface MyMessageViewController ()<UIScrollViewDelegate>


{
    UIScrollView *mainScroll;//创建滑动容器
    MyMessageOneController *oneV;
    MyMessageTwoController *twoV;
}

@end

@implementation MyMessageViewController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
     self.navigationController.navigationBar.hidden = NO;
}
- (IBAction)backBtn:(UIButton *)sender {
      [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureViewCon];
}
- (void)configureViewCon {
    
    _chatBtn.tag = 1000;
    _systeBtn.tag = 1001;
    
    _chatBtn.selected = YES;
    self.tempBtn = _chatBtn;
    [_chatBtn addTarget:self action:@selector(handleBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_systeBtn addTarget:self action:@selector(handleBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //创建一个滑动视图用来滑动Viewcontroller
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 117, kScreen_Width, kScreenHeight-117)];
    //设置代理
    mainScroll.delegate = self;
    mainScroll.scrollEnabled = NO;
    //设置滑动区域
    mainScroll.contentSize = CGSizeMake(kScreen_Width*2, 0) ;
    //打开分页功能
    mainScroll.pagingEnabled = YES;
    //设置背景颜色
    mainScroll.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:mainScroll];
    //设置当前子控制器
    oneV = [[MyMessageOneController alloc] init];
    [self addChildViewController:oneV];
    oneV.view.frame = CGRectMake(0, 0, kScreen_Width, kScreen_Height);
    //将当前的子视图控制器的view添加到主滑动视图上
    [mainScroll addSubview:oneV.view];
    
    
}


- (void)handleBtnAction:(UIButton *)sender {
    if(sender!=self.tempBtn)
    {
        self.tempBtn.selected=NO;self.tempBtn=sender;
    }
    self.tempBtn.selected=YES;
    
    
    mainScroll.contentOffset = CGPointMake(kScreen_Width*(sender.tag - 1000), 0);
    if (mainScroll.contentOffset.x == kScreen_Width) {
        twoV = [[MyMessageTwoController alloc] init];
        [self addChildViewController:twoV];
        twoV.view.frame = CGRectMake(kScreen_Width, 0, kScreen_Width, kScreen_Height);
        [mainScroll addSubview:twoV.view];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
